package com.firewolf.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import utils.ConnectionUtils;

public class Sender {
	private static final String QUEUE_NAME = "queue_msgconfirm_tx";
	public static void main(String[] args) throws Exception {
		
		Connection connection = ConnectionUtils.getMQConnection();
		
		Channel channel = connection.createChannel();
		
		channel.queueDeclare(QUEUE_NAME, false, false, false, null);
		
		channel.txSelect();//开启事务
		
		try{
			channel.basicPublish("", QUEUE_NAME, null, "Hello,MSG confirm !!! ".getBytes());
//			int a = 1/0; //这里产生异常  代码 1
			channel.txCommit();//提交事务
		}catch(Exception e){
			e.printStackTrace();
			channel.txRollback();//产生问题，回滚事务
		}
		
		
	}
}
